package com.sdry.web.controller.zc.quality;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.sdry.model.llm.User;
import com.sdry.model.zc.AbnormalDisposalQuality;
import com.sdry.service.zc.AbnormalDisposalQualityService;
import com.sdry.utils.ResponseUtil;

import net.sf.json.JSONArray;
import net.sf.json.JsonConfig;

/**
 * @ClassName: AbnormalDisposalQualityController 
 * @Description:生产异常处置单品质详情Controller
 * @Author zc
 * @Date 2018年11月2日 下午4:12:04 
 * @version 1.0
 */
@RequestMapping(value="/abnormalDisposalQuality")
@Controller
public class AbnormalDisposalQualityController {

	@Resource
	private AbnormalDisposalQualityService abnormalDisposalQualityService;
	
	/**
	 * 查询生产异常处置单品质详情
	 * @param abnormalDisposalQuality
	 * @param response
	 */
	@RequestMapping(value="/findAbnormalDisposalQualityByAdID")
	public void findAbnormalDisposalQualityByAdID(AbnormalDisposalQuality abnormalDisposalQuality,HttpServletResponse response){
		AbnormalDisposalQuality AbnormalDisposalQuality2 = abnormalDisposalQualityService.findAbnormalDisposalQualityByAdID(abnormalDisposalQuality);
		JsonConfig jsonConfig = new JsonConfig();
		JSONArray jsonArray = JSONArray.fromObject(AbnormalDisposalQuality2, jsonConfig);
		try {
			ResponseUtil.write(response, jsonArray);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	/**
	 * 保存生产异常处置单品质详情
	 * @param abnormalDisposalQuality
	 * @param response
	 */
	@RequestMapping(value="/saveAbnormalDisposalQuality")
	public void saveAbnormalDisposalQuality(AbnormalDisposalQuality abnormalDisposalQuality,String isQualified,HttpServletResponse response,HttpSession session){
		int isSuccess = 0;
		User user = (User) session.getAttribute("currentUser");
		abnormalDisposalQuality.setQualityPerson(user.getUserName());
		isSuccess = abnormalDisposalQualityService.insertAbnormalDisposalQuality(abnormalDisposalQuality,isQualified);
		try {
			ResponseUtil.write(response, isSuccess);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	/**
	 * 修改生产异常处置单品质详情
	 * @param abnormalDisposalQuality
	 * @param response
	 */
	@RequestMapping(value="/updateAbnormalDisposalQuality")
	public void updateAbnormalDisposalQuality(AbnormalDisposalQuality abnormalDisposalQuality,HttpServletResponse response,HttpSession session){
		int isSuccess = 0;
		User user = (User) session.getAttribute("currentUser");
		if (abnormalDisposalQuality.getReserve4() == null || "".equals(abnormalDisposalQuality.getReserve4())) {
			abnormalDisposalQuality.setMakePerson(user.getUserName());
		} else {
			abnormalDisposalQuality.setTechniquePerson(user.getUserName());
		}
		isSuccess = abnormalDisposalQualityService.updateAbnormalDisposalQuality(abnormalDisposalQuality);
		try {
			ResponseUtil.write(response, isSuccess);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
